package com.dyna.foundation.convert;


import cn.hutool.core.bean.BeanUtil;
import com.dyna.core.utils.CollUtil;
import com.dyna.core.utils.MapUtil;
import com.dyna.foundation.domain.entity.SysDept;
import com.dyna.foundation.domain.entity.SysUser;
import com.dyna.foundation.domain.resp.SysUserResp;
import com.dyna.foundation.domain.resp.UserSimpleResp;

import java.util.List;
import java.util.Map;

public class UserConvert {

    public static List<SysUserResp> convertList(List<SysUser> list, Map<Long, SysDept> deptMap) {
        return CollUtil.convertList(list, user -> convert(user, deptMap.get(user.getDeptId())));
    }

    public static SysUserResp convert(SysUser user, SysDept dept) {
        SysUserResp userVO = BeanUtil.toBean(user, SysUserResp.class);
        if (dept != null) {
            userVO.setDeptName(dept.getDeptName());
        }
        userVO.setSex(user.getSex());
        return userVO;
    }

    public static List<UserSimpleResp> convertSimpleList(List<SysUser> list, Map<Long, SysDept> deptMap) {
        return CollUtil.convertList(list, user -> {
            UserSimpleResp userVO = BeanUtil.toBean(user, UserSimpleResp.class);
            MapUtil.findAndThen(deptMap, user.getDeptId(), dept -> userVO.setDeptName(dept.getDeptName()));
            return userVO;
        });
    }

/*    default UserProfileRespVO convert(AdminUserDO user, List<RoleDO> userRoles,
                                      DeptDO dept, List<PostDO> posts) {
        UserProfileRespVO userVO = BeanUtils.toBean(user, UserProfileRespVO.class);
        userVO.setRoles(BeanUtils.toBean(userRoles, RoleSimpleRespVO.class));
        userVO.setDept(BeanUtils.toBean(dept, DeptSimpleRespVO.class));
        userVO.setPosts(BeanUtils.toBean(posts, PostSimpleRespVO.class));
        return userVO;
    }*/

}
